module.exports = function ($scope, $resource, $modal, toaster, getDate) {

	//加载游团列表
	$scope.getTravelList = function(pageNo) {
		$scope.searchform.loading = true;
		var para = {
			'pageNo': pageNo,
			'pageSize': $scope.itemsPerPage,
			'guide_name': $scope.searchform.guide_name,
			'guide_mobile': $scope.searchform.guide_mobile,
			'status': $scope.searchform.status
		}
		$resource('/api/as/goc/outboundtravel/getTravelInfoList', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
				$scope.list = res.data.results;
				$scope.totalItems = res.data.totalRecord;
				$scope.currentPage = pageNo;
				$scope.searchform.loading = false;
            } else {
                toaster.error({title: '', body: '查询出境游信息失败'});
            }
        });
	}
	
	init();
	function init() {
		$scope.currentPage = 1;			//当前页码
		$scope.itemsPerPage = 10;		//每页显示几条
		$scope.searchform = {
			'status': '',
			'statusList': [
				{'label': '全部', 'value': ''},
				{'label': '未上报', 'value': '1'},
				{'label': '已上报', 'value': '2'},
				{'label': '已通过', 'value': '3'},
				{'label': '未通过', 'value': '4'},
			]
		};
		$scope.dictTravel = {
			'a1': '未上报',
			'a2': '已上报',
			'a3': '已通过',
			'a4': '未通过',
		};
		$scope.getTravelList(1);
	}

	//修改
	$scope.update = function(item){
		var modalInstance = $modal.open({
			template: require('../views/outboundSale.html'),
			controller: 'outboundSale',
			size: 'lg',
			resolve: {
				getDate : function(utilservice){
					return utilservice.getDate;
				},
				travel: function () {
					return item;
				},
				flag : function(){
					return true;
				}
			}
		});
		modalInstance.result.then(function (result) {
			item.guide_name = result.guide_name;
			item.guide_mobile = result.guide_mobile;
			item.address = result.address;
        });
	}

	//删除
	$scope.delete = function(item){
		if(confirm('删除此游团后,报名的游客将被删除\r\n确认删除此游团信息吗?')){
			$resource('/api/ac/goc/outboundTravelService/deleteOutboundSale', {}, {}).save({'sale_code':item.sale_code}, function(res){
				if (res.errcode === 0) {
					toaster.success({title: '', body: '删除成功'});
					$scope.getTravelList($scope.currentPage);
				} else {
					toaster.error({title: '', body: res.errmsg});
				}
			});
		}
	}

	//修改游团产品状态
	$scope.setStatus = function(item, status){
		var para = {
			'group_code': item.group_code,
			'sale_code': item.sale_code,
			'status': status
		}
		$resource('/api/ac/goc/outboundTravelService/setSaleStatus', {}, {}).save(para, function(res){
			if (res.errcode === 0) {
				toaster.success({title: '', body: '成功'});
				item.status = status;
			} else {
				toaster.error({title: '', body: '失败'});
			}
		});
	}

	//游客名单
	$scope.infolist = function(item){
		var modalInstance = $modal.open({
			template: require('../views/infolist.html'),
			controller: 'infolist',
			size: 'lg',
			resolve: {
				getDate : function(utilservice){
					return utilservice.getDate;
				},
				travel: function () {
					return item;
				},
				updateFlag: function () {
					return true;
				},
                checkFlag: function () {
                    return false;
                }
			}
		});
	}


};